<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
  <button>GET</button>
  <button>POST</button>
  <button>通用型方法发送ajax</button>
  <script>
    $('button').eq(0).click(function() {
      $.get('http://127.0.0.1:8000/server', {a:100,b:200}, function(data) {
        console.log(data);
      })
    })

    $('button').eq(1).click(function() {
      $.post('http://127.0.0.1:8000/server', {a:100,b:200}, function(data) {
        console.log(data);
      })
    })

    $('button').eq(2).click(function() {
      $.ajax({
        url: 'http://127.0.0.1:8000/server',
        data: {
          a: 100,
          b: 200
        },
        type: 'GET',
        dataType: 'json',
        success: function(data) {
          console.log(data);
        },
        error: function(err) {
          console.log('出错了', err);
        },
        timeout: 2000,
      })
    })
  </script>
</body>
</html>